// Code file original author: Martin Lapierre, http://devinstinct.com

using System;
using System.Text;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using EntLibContrib.Validation.Validators;
using Microsoft.Practices.EnterpriseLibrary.Validation;

namespace EntLibContrib.Validation.Tests.Validators
{
    /// <summary>
    /// Tests <see cref="CollectionCountValidatorAttribute"/>.
    /// </summary>
    [TestClass]
    public class CollectionCountValidatorAttributeFixture
    {
        /// <summary>
        /// Tests valid bounds validation.
        /// </summary>
        [TestMethod]
        public void ReturnsSuccessForValidBounds()
        {
            ObjectValidator<TestTarget> validator = new ObjectValidator<TestTarget>("GoodBounds");
            ValidationResults results = validator.Validate(new TestTarget());

            Assert.IsTrue(results.IsValid);
        }

        /// <summary>
        /// Tests invalid upper bound.
        /// </summary>
        [TestMethod]
        public void ReturnsFailureForBadUpperBound()
        {
            ObjectValidator<TestTarget> validator = new ObjectValidator<TestTarget>("BadUpperBound");
            ValidationResults results = validator.Validate(new TestTarget());

            Assert.IsFalse(results.IsValid);
        }

        /// <summary>
        /// Tests invalid lower bound.
        /// </summary>
        [TestMethod]
        public void ReturnsFailureForBadLowerBound()
        {
            ObjectValidator<TestTarget> validator = new ObjectValidator<TestTarget>("BadLowerBound");
            ValidationResults results = validator.Validate(new TestTarget());

            Assert.IsFalse(results.IsValid);
        }

        /// <summary>
        /// Test target for this fixture.
        /// </summary>
        private class TestTarget
        {
            [CollectionCountValidator(10, Ruleset="GoodBounds")]
            [CollectionCountValidator(0, Ruleset = "BadUpperBound")]
            [CollectionCountValidator(10, 10, Ruleset = "BadLowerBound")]
            public int[] Collection = new int[] { 1, 2, 3, 4, 5 };
        }
    }
}
